import { useBoolean } from 'ahooks'
import { useState } from 'react'

function useModal(defaultValue = {}) {
  const [data, setData] = useState(defaultValue)
  const [visible, { setFalse, setTrue }] = useBoolean()

  function showModal(data) {
    if (data) {
      setData(data)
      setTrue()
    }
    else {
      setTrue()
    }
  }

  return { data, visible, showModal, hideModal: setFalse }
}

export default useModal
